home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 22 code / Paper Juggling / Shell Files / ShellMain.c < prev    next >
Encoding:
Text File  |  1995-03-16  |  4.0 KB  |  167 lines  |  [TEXT/MMCC]

  1. //---------------------------------------------------------------------
  2. //---------------------------------------------------------------------
  3. //
  4. //    Horrible Rickety Shell, by Dave Johnson
  5. //
  6. //    © Copyright 1985 - 1995 Anyone Who Wants It,
  7. //    All Rights Energetically Hurled as far away from me as possible.
  8. //    Use at your own (considerable) risk.
  9.  
  10.  
  11. #include "Shell.h"
  12. #include "DialogUtils.h"
  13.  
  14. Boolean            gDoneFlag = false;
  15. Rect            gDeskRect;
  16. MenuHandle        gShellMenuHandles[kNumShellMenus];
  17. unsigned long    gClickTime, gSleepTime = 0;
  18. short            gDocTitleHeight, gDocFrameWidth;     // Window Stats, for use in positioning
  19.  
  20. // UPPs
  21. AEEventHandlerUPP    gOAPPHandlerUPP, gODOCHandlerUPP, gPDOCHandlerUPP, gQUITHandlerUPP;
  22. ControlActionUPP    gScrollActionUPP;
  23.  
  24. void main (void)
  25. {
  26.        EventRecord        theEvent;
  27.     CursHandle        curs;
  28.     
  29.     FlushEvents (everyEvent - diskMask, 0 );
  30.  
  31.     // Generic heap initialization.
  32.     MaxApplZone(); 
  33.     MoreMasters(); MoreMasters(); MoreMasters(); 
  34.     MoreMasters(); MoreMasters(); MoreMasters(); 
  35.     
  36.     // Start up the toolbox so we can notify people if there's a problem
  37.     
  38.     InitGraf(&qd.thePort);
  39.     InitFonts();
  40.     InitWindows();
  41.     InitMenus();
  42.     TEInit();
  43.     InitDialogs(nil);
  44.     InitCursor();
  45.     
  46.     // Set cursor to watch
  47.     curs = GetCursor(watchCursor);
  48.     SetCursor(*curs);
  49.     
  50.     // Try to start up shell
  51.     if(InitShell() == true)
  52.     {
  53.         // Set cursor back to arrow
  54.         SetCursor(&qd.arrow);
  55.         
  56.         // Loop forever
  57.         while(gDoneFlag == false)
  58.         {
  59.             WaitNextEvent(everyEvent, &theEvent, gSleepTime, nil);
  60.             DoEvent(&theEvent);
  61.         }
  62.     }
  63.     
  64.     BailOut();
  65. }
  66.  
  67. /*-------------------------------------------------------------------------
  68. initshell()            Inits all the application-specific variables...
  69. -------------------------------------------------------------------------*/
  70.  
  71. Boolean InitShell(void)
  72. {
  73.     MenuHandle        mhndl;
  74.     unsigned long    seed;
  75.     OSErr            err;
  76.     
  77.     //  Check for the machine characteristics we need to run 
  78.     if(CheckMachine() == false)
  79.     {
  80.         DoErrorAlert(kWimpyMachineStr, 0);
  81.         return false;
  82.     }
  83.     
  84.     // Check for GX
  85.     if(CheckQuickDrawGX() == false)
  86.     {
  87.         DoErrorAlert(kNoGXStr, 0);
  88.         return false;
  89.     }
  90.     
  91.     // ----------------------------------------------------------------
  92.     // Make upps in the app heap - no need to dispose them at the end.
  93.     
  94.     // Scroll action UPP
  95.     gScrollActionUPP = NewControlActionProc(ScrollActionProc);
  96.  
  97.     // Install the required Apple Event Handlers
  98.     gOAPPHandlerUPP = NewAEEventHandlerProc(OAPPHandler);
  99.     err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gOAPPHandlerUPP, 0, FALSE);
  100.     if(err != noErr)
  101.         return false;
  102.     gODOCHandlerUPP = NewAEEventHandlerProc(ODOCHandler);
  103.      err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, gODOCHandlerUPP, 0, FALSE);
  104.     if(err != noErr)
  105.         return false;
  106.     gPDOCHandlerUPP = NewAEEventHandlerProc(PDOCHandler);
  107.     err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, gPDOCHandlerUPP, 0, FALSE);
  108.     if(err != noErr)
  109.         return false;
  110.     gQUITHandlerUPP = NewAEEventHandlerProc(QUITHandler);
  111.     err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gQUITHandlerUPP, 0, FALSE);
  112.     if(err != noErr)
  113.         return false;
  114.     
  115.     // Build the dialog UPPs
  116.     InitDialogUPPs();
  117.     
  118.     // Set up GX stuff
  119.     if(SetUpGX() == false)
  120.     {
  121.         DoErrorAlert(kNoMemStr, 0);
  122.         return false;
  123.     }
  124.     
  125.     //  Get the window measurements we'll need later 
  126.     CalcWindowStats();
  127.  
  128.     //  Get Bounding box of Desktop  
  129.     gDeskRect = (**GetGrayRgn()).rgnBBox;
  130.     
  131.     //  Reset random number generator  
  132.     GetDateTime(&seed);
  133.     qd.randSeed = seed;
  134.  
  135.     // Read in menus, draw the bar...
  136.     mhndl = GetMenu(kAppleMenuID);
  137.     if(mhndl == nil)
  138.         return false;
  139.     AddResMenu(mhndl, 'DRVR');
  140.     (*mhndl)->menuID = kAppleMenuID;
  141.     InsertMenu(mhndl, 0);
  142.     gShellMenuHandles[kAppleMenu] = mhndl;
  143.     
  144.     mhndl = GetMenu(kFileMenuID);
  145.     if(mhndl == nil)
  146.         return false;
  147.     (*mhndl)->menuID = kFileMenuID;
  148.     InsertMenu(mhndl, 0);
  149.     gShellMenuHandles[kFileMenu] = mhndl;
  150.     
  151.     mhndl = GetMenu(kEditMenuID);
  152.     if(mhndl == nil)
  153.         return false;
  154.     (*mhndl)->menuID = kEditMenuID;
  155.     InsertMenu(mhndl, 0);
  156.     gShellMenuHandles[kEditMenu] = mhndl;
  157.  
  158.     DrawMenuBar();
  159.     
  160.     // Try to Init the App's stuff
  161.     if(AppInit() == false)
  162.         return false;
  163.     
  164.     // success!
  165.     return true;
  166. }
  167.